var util = require("../../../utils/util.js")
const api = require("../../../api/index.js")
let app = getApp();
Page({
  /**
   * 页面的初始数据
   */
  data: {
    imgUrls: [
      'http://img02.tooopen.com/images/20150928/tooopen_sy_143912755726.jpg',
      'http://img06.tooopen.com/images/20160818/tooopen_sy_175866434296.jpg',
      'http://img06.tooopen.com/images/20160818/tooopen_sy_175833047715.jpg'
    ],
    indicatorDots: false,
    autoplay: false,
    interval: 5000,
    duration: 1000,
    Text:'',
    text:'',
    deFault:true,
    textNumber: '',
    show:false,
    hidee: true,
    phone: '',
    venueData: [],
    coursNull:true,
    imgSrc: "",
    urlid:''
  },
  site:function(){
    let lat = Number(this.data.venueData.branch_veidoo);
    let lon = Number(this.data.venueData.branch_long);
    let titleName = this.data.venueData.branch_name;
    let address = this.data.venueData.branch_address
    App.zhuge.track('场馆详情-打开地图导航', {
      '地址': titleName 
    });
    util.siet(lat,lon,titleName,address);
  },
  phone: function (event) {
    var phone;
    App.zhuge.track('场馆详情-打开电话', {
      '电话': data
    });
    var data = event.currentTarget.dataset.phone;
    util.phone(data, this.data.venueData.branch_tel);
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let urlid = options.id;
    this.setData({
      urlid: urlid
    })
    this.getVenueData(urlid)
    this.setData({
      imgSrc: api.imgPathUrl
    })
  },
  judge:function(){ //字体判断
     let  tetLength = this.data.text.length;
      if (tetLength > 100){
        this.setData({
          deFault: !this.data.deFault,
          show: !this.data.show,
          hidee: !this.data.hidee
        })
      }
    
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    //let Id = parseInt(getCurrentPages()[1].options.id);
    //this.getVenueData(Id)
    // this.onLoad();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function (options) {
    let th = this;
    return {
      title: '',
      // path: "/pages/lookVennue/lookVennue/lookVennue",
       path: "/pages/lookVennue/venue/venue?id=" + th.data.urlid
    }                                                      
  },
  getVenueData: function(id){
    let data ={
      branch_id :id,
      longitude: wx.getStorageSync('key').longitude,
      latitude: wx.getStorageSync('key').latitude 
    }
    wx.showLoading({
      title: '加载中',
    })
    api.vennueDetails(data, (res) => {
      App.zhuge.track('打开场馆页面', {
        '场馆名称及详情': res.data.result.branch_name
      });
      if (res.data.code == 200) {
        setTimeout(function () {
          wx.hideLoading()
        }, 500)
      }
      var Text;
      if (res.data.result.branch_desc.length > 100){
        Text =  res.data.result.branch_desc.slice(0, 100) + '...';
      }else{
        Text = res.data.result.branch_desc;
      }  
      this.setData({
        Text: Text
      })
      if (res.data.result.branch_desc.length > 100){
        this.setData({
          textNumber:true,
          text:res.data.result.branch_desc, 
        })
      }
      this.setData({
        "venueData": res.data.result,
      })
      wx.setNavigationBarTitle({ title: this.data.venueData.branch_name })
    })
  },
  ChooseClass: function (e) {
    let VueneName = e.currentTarget.dataset.name;
    App.zhuge.track('场馆下面点击的课程', {
      '课程名称': VueneName
    });
  }
})